package shortcircuit.engine;

import shortcircuit.Display;
import shortcircuit.basics.Environment;
import shortcircuit.basics.EnvironmentPane;
import shortcircuit.basics.PowerUp;
import shortcircuit.basics.powerup.Bomb;
import shortcircuit.basics.powerup.Null;
import shortcircuit.graphics.BeginGameScreen;
import shortcircuit.graphics.GameScreen;
import shortcircuit.graphics.InstructionsScreen;
import shortcircuit.graphics.MainMenuScreen;
import shortcircuit.utilities.FileIO;

/**
 * Creates a new Engine specifically for running the How To Play section.  This extends off of
 * PuzzleEngine and makes several layout modifications to Display in order to have the GameScreen
 * on the right hand side of the screen.  The StatsScreen is then replaced with text on a panel.
 * @author Kevin Lewi
 *
 */
public class InstructionsEngine extends PuzzleEngine
{
	public InstructionsScreen instructionsScreen;

	public InstructionsEngine(Display theDisplay)
	{
		super(theDisplay, 1);
	}

	public void initializeScreens(int theLevel)
	{
		mapReader = new FileIO("maps/instructions" + theLevel + ".scmap", FileIO.READ);
		Environment env = mapReader.readMap();
		numberOfMoves = mapReader.getNumberOfMoves();
		EnvironmentPane ep = new EnvironmentPane(env);
		super.createMap(ep);
		instructionsScreen = new InstructionsScreen(this);
		instructionsScreen.setLocation(0, 0);
		instructionsScreen.setSize(200, 420);
	}

	public void startLevel(int theLevel)
	{
		_Level = theLevel;
		popUpScreen = new BeginGameScreen(2, this);
		if(theLevel < 5)
		{
			mapReader = new FileIO("maps/instructions" + theLevel + ".scmap", FileIO.READ);
			Environment env = mapReader.readMap();
			numberOfMoves = mapReader.getNumberOfMoves();
			blocksToRemove = mapReader.getBlocksToRemove();
			int[] powerUpArray = mapReader.powerUpArray;
			for(int i = 0; i < powerUpArray.length; i++)
			{
				PowerUp thePowerUp = new Null();
				switch(powerUpArray[i])
				{
				case 1: thePowerUp = new Bomb();
				}
				powerUps.add(i, thePowerUp);
			}
			EnvironmentPane ep = new EnvironmentPane(env);
			super.createMap(ep);

			gameScreen = new GameScreen(this);
			gameScreen.setLocation(200, 0);
			gameScreen.setSize(240, 420);
		}
		_Display.clearScreens();
		_Display.directlyAddScreen(popUpScreen, 0);
		_Display.directlyAddScreen(instructionsScreen, 1);
		_Display.directlyAddScreen(gameScreen, 2);
		_Display.directlyAddScreen(MainMenuScreen.bgPanel, 3);
	}

	public void beginLevel(int theLevel)
	{
		initializeScreens(theLevel);
		startLevel(theLevel);
	}

	public void checkEndGame()
	{

	}
}
